﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Admin.Presentation.Controllers
{
    [Authorize]
    [EnsureSsl]
    public class DailyPrayersController : Controller
    {
        [AppendLayoutViewModel]
        public ActionResult Index()
        {
            
            var model = Business.DailyPrayers.Index.PageLoad();
            ViewBag.Message = Request["msg"];
            return View(model);
        }

        [AppendLayoutViewModel]
        public ActionResult CreateLocation(int id)
        {
            
            var model = Business.DailyPrayers.CreateLocation.PageLoad(id);
            return View(model);
        }

        public JsonResult SaveLocation(Adams.Admin.DataTransfer.DailyPrayers.CreateLocation.FormInput input)
        {
            var model = Business.DailyPrayers.CreateLocation.SaveLocation(input);
            return Json(model);
        }

        public RedirectResult DeleteLocation(int id)
        {
            Business.DailyPrayers.Index.DeleteLocation(id);
            var model = new { Deleted = true };
            return Redirect("/DailyPrayers?msg=2");
        }

        [AppendLayoutViewModel]
        public ActionResult CreatePrayer(int id)
        {
            
            int month = Request["month"].ToInt();
            var model = Business.DailyPrayers.CreatePrayer.PageLoad(id, month);
            return View(model);
        }

        public JsonResult SavePrayers(Adams.Admin.DataTransfer.DailyPrayers.CreatePrayer.FormInput input)
        {
            var model = Business.DailyPrayers.CreatePrayer.SavePrayers(input);
            return Json(model);
        }
    }
}
